package com.arcvideo.acsconnect.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.arcvideo.acsconnect.listener.OnUserHeadInfoListener;
import com.arcvideo.tyingyitonginhouse.R;
import com.bumptech.glide.Glide;
import com.framework.core.widget.CircleImageView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author shenmengchao
 * @version 1.0.0
 * @date 2017/11/14
 * @description
 */

public class UserHeadInfoLayout extends LinearLayout {

    @BindView(R.id.civ_avatar)
    CircleImageView mCivAvatar;
    @BindView(R.id.tv_nickname)
    TextView mTvNickname;
    private Context mContext;

    public UserHeadInfoLayout(Context context) {
        this(context, null);
    }

    public UserHeadInfoLayout(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public UserHeadInfoLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        init();
    }

    public void setAvatar(String url) {
        if (TextUtils.isEmpty(url)) {
            mCivAvatar.setVisibility(View.GONE);
        } else {
            mCivAvatar.setVisibility(View.VISIBLE);
            Glide.with(mContext).load(url).into(mCivAvatar);
        }
    }

    public void setNickname(String nickname) {
        if (!TextUtils.isEmpty(nickname)) {
            mTvNickname.setText(nickname);
        }
    }

    private void init() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.layout_user_head_info, this, true);
        ButterKnife.bind(this, view);
    }

}
